package cn.pegasus.teamwork.pegasus.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.pegasus.teamwork.pegasus.entity.BussServicePageage;
import cn.pegasus.teamwork.pegasus.entity.BussServiceProject;
import cn.pegasus.teamwork.pegasus.mapper.BussServicePageageMapper;
import cn.pegasus.teamwork.pegasus.service.BussServicePageageService;
import cn.pegasus.teamwork.util.DateCompareUtil;
import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.iyizhan.teamwork.base.util.PageHelper;
import cn.iyizhan.teamwork.base.util.PageObject;

/**
 * @author ryan.bian
 * @version 
 */
@Service("bussServicePageageService")
public class BussServicePageageServiceImpl extends BaseServiceImpl<BussServicePageage, BussServicePageageMapper> implements BussServicePageageService {
	// 注入当前dao对象
    @Autowired
    private BussServicePageageMapper bussServicePageageMapper;

    public BussServicePageageServiceImpl() {
        setMapperClass(BussServicePageageMapper.class, BussServicePageage.class);
    }

	@Override
	public String getPageageName(Long id) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		return bussServicePageageMapper.getPageageName(map);
	}

	@Override
	public PageObject<BussServicePageage> PageList(Map<String, Object> map) {
		int totalData = bussServicePageageMapper.getTotal(map);
        PageHelper pageHelper = new PageHelper(totalData, map);
        List<BussServicePageage> list = bussServicePageageMapper.findListByPage(pageHelper.getMap());
        PageObject<BussServicePageage> pageObject = pageHelper.getPageObject();
        pageObject.setDataList(list);
		return pageObject;
	}

	@Override
	public void addPageage(Long id,Map<String, Object> map) {
		BussServicePageage pageage = M2O(map);
		//获取自增ID
		
		Long pageageId = bussServicePageageMapper.pageageId();
		if(pageageId == null){
			pageageId = 1L;
		}else{
			pageageId = pageageId + 1L;
		}
		if(null != pageage.getPageagePrice()){
			pageage.setPageagePrice(pageage.getPageagePrice()*100);
		}
		String code = DateCompareUtil.getDateString("yyyyMMdd")+pageageId;
		pageage.setPageageCode(code);
		pageage.setCreateTime(new Date());
		pageage.setCreateUserBy(id);
		pageage.setUpdateTime(new Date());
		pageage.setUpdateUserBy(id);
		pageage.setClassicStatus(0);
		bussServicePageageMapper.insertByEntity(pageage);
	}

	@Override
	public void updatePageage(Long id,Map<String, Object> map) {
		BussServicePageage pageage = M2O(map);
		if(null != pageage.getPageagePrice()){
			pageage.setPageagePrice(pageage.getPageagePrice()*100);
		}
		pageage.setUpdateTime(new Date());
		pageage.setUpdateUserBy(id);
		bussServicePageageMapper.updateByEntity(pageage);
	}

	@Override
	public BussServicePageage findPageageInfo(Long id) {
		BussServicePageage s = new BussServicePageage();
		s.setId(id);
		return bussServicePageageMapper.selectSingle(s);
	}

	@Override
	public void delete(Long userId,Long id) {
		BussServicePageage pageage = new BussServicePageage();
		pageage.setId(id);
		pageage.setClassicStatus(1);
		pageage.setUpdateTime(new Date());
		pageage.setUpdateUserBy(id);
		bussServicePageageMapper.updateByEntity(pageage);
	}
 
}
